#include <algorithm>
#include <cctype>
#include <cstdio>
const int N = 50005;

int n, q;
int h[N];
struct Node {
  int max, min;
  Node() {}
  Node(int _max, int _min) : max(_max), min(_min) {}
} tr[N << 2];

inline int read() {
  int x = 0, ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return x;
}

Node query(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return tr[x];
  int mid = (l + r) >> 1;
  Node res(0, 0x3fffffff);
  if (L <= mid) {
    Node ql = query(x << 1, l, mid, L, R);
    res.max = std::max(res.max, ql.max);
    res.min = std::min(res.min, ql.min);
  }
  if (mid < R) {
    Node qr = query(x << 1 | 1, mid + 1, r, L, R);
    res.max = std::max(res.max, qr.max);
    res.min = std::min(res.min, qr.min);
  }
  return res;
}
void pushup(int x) {
  int ls = x << 1, rs = x << 1 | 1;
  tr[x].max = std::max(tr[ls].max, tr[rs].max);
  tr[x].min = std::min(tr[ls].min, tr[rs].min);
}
void build(int x, int l, int r) {
  if (l == r) {
    tr[x].max = h[l], tr[x].min = h[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  pushup(x);
}
int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("cows.in", "r", stdin);
  freopen("cows.out", "w", stdout);
#endif
#endif

  n = read(), q = read();
  for (int i = 1; i <= n; ++i) {
    h[i] = read();
  }
  build(1, 1, n);
  int a, b;
  while (q--) {
    a = read(), b = read();
    Node tmp = query(1, 1, n, a, b);
    printf("%d\n", tmp.max - tmp.min);
  }
  return 0;
}